#include "Main.h"

byte* cnpcdialogPtr;
byte* QuestAcceptFunctionPtr;
byte* QuestRewardFunctionPtr;

void CNpcDialog::Init()
{
	__try {
		cnpcdialogPtr = (byte*)(*(dword*)Mem->GetAddress("CNpcDialogPtr"));
		QuestAcceptFunctionPtr = Mem->GetAddress("QuestAcceptFunction");
		QuestRewardFunctionPtr = Mem->GetAddress("QuestRewardFunction");
	}
	__except(1) { }
}

unsigned long CNpcDialog::GetSelectedQuestId()
{
	if(!cnpcdialogPtr)
		return NULL;

	return *(dword*)(cnpcdialogPtr + 0x58);
}

void CNpcDialog::AcceptQuest(unsigned long questId)
{
	if(!cnpcdialogPtr || !QuestAcceptFunctionPtr)
		return;

	byte* dialogFramePtr = (byte*)(*(dword*)(cnpcdialogPtr + 0x10));

	*(dword*)(cnpcdialogPtr + 0x58) = questId;

	_asm {
		PUSH dialogFramePtr
		MOV ECX,cnpcdialogPtr
		CALL QuestAcceptFunctionPtr
	}
}

void CNpcDialog::RewardQuest(unsigned long questId)
{
	if(!cnpcdialogPtr || !QuestRewardFunctionPtr)
		return;

	byte* dialogFramePtr = (byte*)(*(dword*)(cnpcdialogPtr + 0x54));

	*(dword*)(cnpcdialogPtr + 0x58) = questId;

	_asm {
		PUSH dialogFramePtr
		MOV ECX,cnpcdialogPtr
		CALL QuestRewardFunctionPtr
	}
}